using IQIGame.Onigao.Game;
using IQIGame.Onigao.GamePlay;

namespace IQIGame.Onigao.Logic
{
    public class LgRecastUtility
    {
        public static Vector3Logic RecastPos2PosInCM(float[] src)
        {
            return new Vector3Logic(
                (-src[0] * LgLevelConst.DistanceUnitRatio),
                (src[1] * LgLevelConst.DistanceUnitRatio),
                (src[2] * LgLevelConst.DistanceUnitRatio)
                );
        }

        public static void PosInCM2RecastPos(Game.Vector3Logic src, float[] dest)
        {
            dest[0] = -src.x / LgLevelConst.DistanceUnitRatio;
            dest[1] = src.y / LgLevelConst.DistanceUnitRatio;
            dest[2] = src.z / LgLevelConst.DistanceUnitRatio;
        }

        public static void ObstacleInfo2RecastBox(Vector3Logic entityPos, ObstacleInfo info, float[] center, float[] halfBounds, float rotationY)
        {
            Vector3Logic finalPos;
            if (info.x == 0 && info.y == 0)
            {
                finalPos = entityPos;
            }
            else
            {
                if (rotationY == 0)
                {
                    finalPos = entityPos + new Vector3Logic(info.x, 0, info.y);
                }
                else
                {
                    var rotatedOffset = LgMathUtil.RotateOffset(new Vector3Logic(info.x, 0, info.y), rotationY);
                    finalPos = entityPos + rotatedOffset;
                }
            }
            center[0] = -finalPos.x / LgLevelConst.DistanceUnitRatio;
            center[1] = (entityPos.y + (float)info.height / 2) / LgLevelConst.DistanceUnitRatio;
            center[2] = finalPos.z / LgLevelConst.DistanceUnitRatio;
            halfBounds[0] = (float)info.rectW / 2 / LgLevelConst.DistanceUnitRatio;
            halfBounds[1] = (float)info.height / 2 / LgLevelConst.DistanceUnitRatio;
            halfBounds[2] = (float)info.rectH / 2 / LgLevelConst.DistanceUnitRatio;
        }
    }
}
